package com.yys.huarongdao;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.yys.huarongdao.application.MyApplication;


public class RankActivity extends AppCompatActivity {

    private RadioGroup rg_ranks;
    private Button but_submit_rank;
    private int rankType;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getSupportActionBar()!=null){
            getSupportActionBar().hide();
        }
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_rank);
        initData();
        bindView();
    }

    private void bindView(){
        rg_ranks = findViewById(R.id.rg_ranks);
        but_submit_rank = findViewById(R.id.but_submit_rank);

        int checked_index=rankType-MyApplication.RANK_3X3;
        RadioButton checked_rbut=(RadioButton)rg_ranks.getChildAt(checked_index);
        checked_rbut.setChecked(true);

        but_submit_rank.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int checkedId = rg_ranks.getCheckedRadioButtonId();
                int rankType=checkedId==R.id.rbut_rank5 ? MyApplication.RANK_5x5:checkedId==R.id.rbut_rank4 ? MyApplication.RANK_4X4:MyApplication.RANK_3X3;
                MyApplication.getApplication().setRankType(RankActivity.this,rankType);
                finish();
            }
        });
    }

    private void initData(){
        rankType=MyApplication.getApplication().getRankType(this);
    }
}
